<?php
    
    class System extends Admin{
    	
		public function __construct(){
			parent::__construct();
			if(!$_SESSION['U']['adminid']){
				$this->showmessage("您还未登录","?m=Admin/Login" ,2000, "管理员登录");
			}else{
				$this->_T['U'] = $_SESSION['U'];
				$this->template();
			}
		}
		
		
		public function Index(){
			$this->mod = "Index";
			$this->_T['adminNum']  = DB::num_rows("select * from `ntwt_admin` where 1");
			$this->_T['memberNum'] = DB::num_rows("select * from `ntwt_user` where 1");
			$this->_T['U']['loginIp']   = $_SERVER["REMOTE_ADDR"];
			$this->template("parent");
		}
		
		public function Announcement(){
			$this->mod = "Announcement";
			$announcement = DB::fetch_row("select * from `ntwt_site_con` where `id`='1'");
			$this->_T['announcement'] =  $announcement;
			$this->template("parent");
		}
		
		public function UpdateAnnouncement(){
			if(!$_POST['anno']){
				$this->showmessage("内容不能为空","goback" ,2000, "公告发布");
			}
			$site_con = array();
			$site_con['con'] = $_POST['anno'];
			$condition = array();
			$condition['id'] = 1;
			if(DB::update("ntwt_site_con", $site_con,$condition)){
				$this->showmessage("更新成功","?m=Admin/System/Announcement" ,2000, "公告发布");
			}
			$this->showmessage("更新失败","goback" ,2000, "公告发布");
		}
		
		public function DevelopersInfo(){
			$this->mod = "DevelopersInfo";
			$editor = new Editor("edit");
			$editor->setmaxWords(5000);
			$this->_T['editorHeader'] = $editor->getHeaderHtml();
			$this->_T['editor'] = $editor->getEditorHtml();
			$developersInfo = DB::fetch_row("select * from `ntwt_site_con` where `id`='2'");
			$this->_T['developersInfo'] =  $developersInfo;
			$this->template("parent");
		}
		
		
		public function UpdateDevelopersInfo(){
			if(!$_POST['edit']){
				$this->showmessage("内容不能为空","goback" ,2000, "开发者信息编辑");
			}
			$site_con = array();
			$site_con['con'] = $_POST['edit'];
			$condition = array();
			$condition['id'] = 2;
			if(DB::update("ntwt_site_con", $site_con,$condition)){
				$this->showmessage("更新成功","?m=Admin/System/DevelopersInfo" ,2000, "公告发布");
			}
			$this->showmessage("更新失败","goback" ,2000, "开发者信息编辑");
		}
		
		public function Share(){
			$this->mod = "Share";
			$share = DB::fetch_row("select * from `ntwt_site_con` where `id`='3'");
			$this->_T['share'] =  $share;
			$this->template("parent");
		}
		
		public function UpdateShare(){
			if($_POST['sharecon']){
				$this->showmessage("内容不能为空","goback" ,2000, "开发者信息编辑");
			}
			$site_con = array();
			$site_con['con'] = $_POST['sharecon'];
			$condition = array();
			$condition['id'] = 3;
			if(DB::update("ntwt_site_con", $site_con,$condition)){
				$this->showmessage("更新成功","?m=Admin/System/Share" ,2000, "分享设置");
			}
			$this->showmessage("更新失败","goback" ,2000, "开发者信息编辑");
		}
		
		public function MessageList(){
			$this->mod = "MessageList";
			$page = new Page(8,"select * from `ntwt_message` as m left join `ntwt_user` as u on 
			                m.uid = u.uid where m.`sign` = '0'");
			$this->_T['PageList']['con']      = $page->content;
			$this->_T['PageList']['rowNum'] = $page->num;
			$this->_T['PageList']['pageOne']  = $page->first_page;
			$this->_T['PageList']['pageLast'] = $page->last_page;
			$this->_T['PageList']['pageVal']  = $page->pageval;
			$this->_T['PageList']['pagePre']  = $page->pageval-1;
			$this->_T['PageList']['pageNext'] = $page->pageval+1;
			$this->template("parent");
		}
		
		public function DealMessage(){
			$id = intval($_GET['id']);
			$sign = intval($_GET['sign']);
			if(!DB::fetch_row("select * from `ntwt_message` where `id` = '{$id}'")){
				$this->showmessage("留言不存在", "goback", 2000, "留言列表");
			}else{
				$data = array();
				$data['sign'] = $sign;
				$condition = array();
				$condition['id'] = $id;
				if(DB::update("ntwt_message", $data, $condition)){
					$this->showmessage("留言已审核", "?m=Admin/System/MessageList", 2000, "留言列表");
				}
				$this->showmessage("审核失败", "goback", 2000, "留言列表");
			}
					
		}
		
    }
